package com.xydtech.ecard.config.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xydtech.common.annotation.Log;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.ecard.config.domain.EcardPosterConfigure;
import com.xydtech.ecard.config.service.IEcardPosterConfigureService;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.common.core.page.TableDataInfo;

/**
 * 海报配置Controller
 * 
 * @author xydtech
 * @date 2022-12-05
 */
@Controller
@RequestMapping("/config/posterConfigure")
public class EcardPosterConfigureController extends BaseController
{
    private String prefix = "config/posterConfigure";

    @Autowired
    private IEcardPosterConfigureService ecardPosterConfigureService;

    @RequiresPermissions("config:posterConfigure:view")
    @GetMapping()
    public String posterConfigure()
    {
        return prefix + "/posterConfigure";
    }

    /**
     * 查询海报配置列表
     */
    @RequiresPermissions("config:posterConfigure:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardPosterConfigure ecardPosterConfigure)
    {
        startPage();
        List<EcardPosterConfigure> list = ecardPosterConfigureService.selectEcardPosterConfigureList(ecardPosterConfigure);
        return getDataTable(list);
    }

    /**
     * 导出海报配置列表
     */
    @RequiresPermissions("config:posterConfigure:export")
    @Log(title = "海报配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardPosterConfigure ecardPosterConfigure)
    {
        List<EcardPosterConfigure> list = ecardPosterConfigureService.selectEcardPosterConfigureList(ecardPosterConfigure);
        ExcelUtil<EcardPosterConfigure> util = new ExcelUtil<EcardPosterConfigure>(EcardPosterConfigure.class);
        return util.exportExcel(list, "海报配置数据");
    }

    /**
     * 新增海报配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存海报配置
     */
    @RequiresPermissions("config:posterConfigure:add")
    @Log(title = "海报配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardPosterConfigure ecardPosterConfigure)
    {
        return toAjax(ecardPosterConfigureService.insertEcardPosterConfigure(ecardPosterConfigure));
    }

    /**
     * 修改海报配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EcardPosterConfigure ecardPosterConfigure = ecardPosterConfigureService.selectEcardPosterConfigureById(id);
        mmap.put("ecardPosterConfigure", ecardPosterConfigure);
        return prefix + "/edit";
    }

    /**
     * 修改保存海报配置
     */
    @RequiresPermissions("config:posterConfigure:edit")
    @Log(title = "海报配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardPosterConfigure ecardPosterConfigure)
    {
        return toAjax(ecardPosterConfigureService.updateEcardPosterConfigure(ecardPosterConfigure));
    }

    /**
     * 删除海报配置
     */
    @RequiresPermissions("config:posterConfigure:remove")
    @Log(title = "海报配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ecardPosterConfigureService.deleteEcardPosterConfigureByIds(ids));
    }
}
